//分类业务相关代码
import { ref } from "vue";
import { onMounted } from "vue";
import { useRoute } from "vue-router";
import { getCategoryAPI } from "@/apis/category.js";
import {onBeforeRouteUpdate} from 'vue-router'
export function useCategory(){
    const categoryData = ref({});
    const route = useRoute();
    const getCategory = async (id = route.params.id) => {
      const res = await getCategoryAPI(id );
      categoryData.value = res.result;
    };
    onBeforeRouteUpdate((to)=>{
      getCategory(to.params.id)
  })
    onMounted(() => {
      getCategory();
    });
    return {
        categoryData
    }
}
